package com.frank.circle.service.impl;

import com.alibaba.fastjson2.JSON;
import com.frank.circle.entity.ShareMoment;
import com.frank.circle.enums.MomentReplyCountEnum;
import com.frank.circle.mapper.ShareMomentMapper;
import com.frank.circle.req.SaveMomentReq;
import com.frank.circle.service.MomentService;
import com.frank.common.enums.IsDeletedFlagEnum;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author Frank Zou
 * @version v0.0.1
 * @date 2025/10/16
 * @description
 */
@Service
public class MomentServiceImpl implements MomentService {

    private final ShareMomentMapper shareMomentMapper;

    public MomentServiceImpl(ShareMomentMapper shareMomentMapper) {
        this.shareMomentMapper = shareMomentMapper;
    }


    @Override
    public Boolean saveMoment(SaveMomentReq req) {
        ShareMoment shareMoment = new ShareMoment();
        shareMoment.setCircleId(req.getCircleId())
                .setContent(req.getContent())
                .setPicUrls(JSON.toJSONString(req.getPicUrlList()))
                .setReplyCount(MomentReplyCountEnum.COMMENT.getValue())
                .setCreatedTime(new Date())
                .setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
        return shareMomentMapper.insert(shareMoment) > 0;
    }
}
